package com.example.service;

import com.example.entity.Singer;
import com.example.mapper.SingerMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * 歌手信息表业务处理
 **/
@Service
public class SingerService {

    @Resource
    private SingerMapper singerMapper;

    /**
     * 新增
     */
    public void add(Singer singer) {
        singerMapper.insert(singer);
    }

    /**
     * 删除
     */
    public void deleteById(Integer id) {
        singerMapper.deleteById(id);
    }

    /**
     * 批量删除
     */
    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids) {
            singerMapper.deleteById(id);
        }
    }

    /**
     * 修改
     */
    public void updateById(Singer singer) {
        singerMapper.updateById(singer);
    }

    /**
     * 根据ID查询
     */
    public Singer selectById(Integer id) {
        return singerMapper.selectById(id);
    }

    /**
     * 查询所有
     */
    public List<Singer> selectAll(Singer singer) {
        return singerMapper.selectAll(singer);
    }

    /**
     * 分页查询
     */
    public PageInfo<Singer> selectPage(Singer singer, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Singer> list = singerMapper.selectAll(singer);
        return PageInfo.of(list);
    }

    public List<Singer> selectTop(Integer num) {
        return singerMapper.selectTop(num);
    }
}